package com.yequan.spring.bean.factory;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author : Administrator
 * @date : 2020/4/3
 */
public class DefaultUserFactory implements UserFactory, InitializingBean, DisposableBean {

    /**
     * 1.@PostConstruct初始化
     */
    @PostConstruct
    public void init() {
        System.out.println("@PostConstruct : 初始化中...");
    }

    /**
     * 2.自定义初始化方法
     */
    public void initUserFactory() {
        System.out.println("自定义初始化方法 initUserFactory: 初始化中...");
    }

    /**
     * 3.实现InitializingBean接口的afterPropertiesSet初始化
     *
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("实现InitializingBean接口的afterPropertiesSet: 初始化中...");
    }

    /**
     * 1.@PreDestroy销毁
     */
    @PreDestroy
    public void destroyBean() {
        System.out.println("@PreDestroy : 销毁中...");
    }

    /**
     * 2.实现DisposableBean接口的destroy方法销毁
     *
     * @throws Exception
     */
    @Override
    public void destroy() throws Exception {
        System.out.println("DisposableBean#destroy : 销毁中...");
    }

    /**
     * 3.自定义销毁方法
     */
    public void destroyCustom() {
        System.out.println("自定义销毁方法 destroyCustom : 销毁中...");
    }

    @Override
    public void finalize() throws Throwable {
        System.out.println("当前 DefaultUserFactory 对象正在被回收...");
    }
}
